package day_2022_9_to_12.Day;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author haomin
 * @date 2022/09/11 10:29
 **/
public class Day9_2_Num6176_MostFrequentEven {
    class Solution {
        public int mostFrequentEven(int[] nums) {
            if(nums.length == 0) return 0;
            Arrays.sort(nums);
            int max = 0, ans = 0;
            Map<Integer, Integer> map = new HashMap<>();
            for(int i : nums){
                if(i % 2 != 0) continue;
                map.put(i, map.getOrDefault(i, 0)+1);
                if(map.get(i) > max){
                    max = map.get(i);
                    ans = i;
                }
            }
            if(map.size() == 0) return -1;
            return ans;
        }
    }
}